package com.fengke.util;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.perf4j.*;
import org.perf4j.log4j.Log4JStopWatch;

public class ControlServiceInterceptor{

	private StopWatch stopWatch;

	public void before(JoinPoint jp){
		stopWatch = new Log4JStopWatch();
	}

	public void afterReturning(JoinPoint jp) {
		String classFullName = jp.getTarget().getClass().toString();
		String className = classFullName.substring(classFullName.lastIndexOf(".")+1);
		stopWatch.stop(className + "." + jp.getSignature().getName());
	}
	
	public Object around(ProceedingJoinPoint jp) throws Throwable {
		stopWatch = new Log4JStopWatch();
		
		Object retVal = jp.proceed();
		String classFullName = jp.getTarget().getClass().toString();
		String className = classFullName.substring(classFullName.lastIndexOf(".")+1);
		stopWatch.stop(className + "." + jp.getSignature().getName());
		return retVal;
	}
}
